﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cjhushi
{
    
    public class ChairCrisis
    {
        
        class Lecture
        {
            public int beginTime;
            public int endTime;
            public int numberOfChairs;
            public Lecture(int beginTime,int endTime,int numberOfChairs)
            {
                this.beginTime = beginTime;
                this.endTime = endTime;
                this.numberOfChairs = numberOfChairs;
            }
        }
        private int numberOfLectures;
        private Lecture[] lectures = new Lecture[1009];
        private int[] numberOfChairsIndateTime = new int[1009];
         public ChairCrisis()
        {

        }
        private void handleInput(string input)
        {
            string[] strInput = input.Split(" ");
            numberOfLectures = int.Parse(strInput[0]);
            for (int i = 1; i < numberOfLectures; i++)
            {
                Lecture lecture= new Lecture(Convert.ToInt32(strInput[(i-1)*3+1]),Convert.ToInt32(strInput[(i - 1) * 3 + 2]),Convert.ToInt32(strInput[(i - 1) * 3 + 3]));
                lectures[i-1]=lecture;
            }
        }
        public int calculateChairs()
        {
            for(int i=0;i<numberOfLectures;i++)
            {
                int chair = lectures[i].numberOfChairs;
                int beginTime = lectures[i].beginTime;
                int releaseTime = lectures[i].endTime = 5;
                numberOfChairsIndateTime[beginTime] += chair;
                numberOfChairsIndateTime[releaseTime] -= chair;
            }
            int[] s = new int[1009];
            for(int i=1;i<=1000;i++)
            {
                s[i] = s[i - 1] + numberOfChairsIndateTime[i];
            }
            return s.Max();
        }
    }
}
